package com.xiong.wuliao.util;

import com.xiong.wuliao.entity.TwoStory;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 解析图和和少女心等页面的数据
 * Created by Administrator on 2016/11/7.
 */
public class TwoSpecialJSON {

    public static List<TwoStory> saveTwoSpecialData(String s) {
        List<TwoStory> twoStoryList = new ArrayList<>();
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(s.trim());
            JSONObject object = jsonObject.optJSONObject("data");
            JSONArray array = object.optJSONArray("posts");
            for (int index = 0; index < array.length(); index++) {
                JSONObject obj = array.optJSONObject(index);
                TwoStory story = new TwoStory();

                story.setContent_url(obj.optString("content_url"));
                story.setCover_image_url(obj.optString("cover_image_url"));
                story.setCreated_at(obj.optString("created_at"));
                story.setId(obj.optString("id"));
                story.setLiked(obj.optBoolean("liked"));
                story.setLikes_count(obj.optString("likes_count"));
                story.setPublished_at(obj.optString("published_at"));
                story.setShare_msg(obj.optString("share_msg"));
                story.setTitle(obj.optString("title"));
                story.setUpdated_at(obj.optString("updated_at"));
                story.setUrl(obj.optString("url"));

                twoStoryList.add(story);
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return twoStoryList;
    }
}
